/*
 * @(#)MessageServiceImpl.java 2011-12-08
 *
 * Copyright 2011 北龙中网（北京）科技有限责任公司. All rights reserved.
 */
package cn.shangjia.shop.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.shangjia.common.domain.support.MessageType;
import cn.shangjia.common.exceptions.Logger;
import cn.shangjia.common.webservice.bean.NormalMessage;
import cn.shangjia.common.webservice.exception.MessageException;
import cn.shangjia.common.webservice.ws.MessageWebService;
import cn.shangjia.shop.config.Constants;
import cn.shangjia.shop.log.ShopLoggerFactory;
import cn.shangjia.shop.service.MessageService;

/**
 *
 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
 * @version 1.0, 2011-12-08 16:07:37
 * @since 1.0
 */
@Service
public class MessageServiceImpl implements MessageService{
	
	private static final Logger logger = ShopLoggerFactory.getLogger(MessageService.class);
	
	@Resource
	private MessageWebService messageWebServiceClient;
	
	/*
	 * (non-Javadoc)
	 * @see cn.shangjia.shop.service.MessageService#addNormalMessage(cn.shangjia.common.webservice.bean.NormalMessage)
	 */
	@Override
	public void addNormalMessage(final NormalMessage normalMessage) {
		normalMessage.setMessageType(MessageType.SHOP);
		Constants.webserviceExecutorService.execute(new Runnable() {
			@Override
			public void run() {
				try {
					messageWebServiceClient.sendMessage(normalMessage);
				} catch (MessageException e) {
					logger.error(e);
				}
			}
		});
	}
	
}
